{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install --upgrade wormpose"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We first download some util functions to display images:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!wget https://raw.githubusercontent.com/iteal/wormpose/main/examples/ipython_utils.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Set the filename of the tfrecord file to inspect:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ex: tfrecord_filename = /path/to/train0.tfrecord\n",
    "tfrecord_filename = \"PATH_TO_TFRECORD\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Display the frames from the tfrecord, you can also view the associated labels."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from wormpose.machine_learning import tfrecord_file\n",
    "from ipython_utils import ImagesViewer\n",
    "\n",
    "if not os.path.isfile(tfrecord_filename):\n",
    "    raise FileNotFoundError(tfrecord_filename)\n",
    "\n",
    "MAX_AMOUNT = 100\n",
    "\n",
    "# Update this value if you used a different posture model than the provided PosturesModel\n",
    "theta_dims = 100\n",
    "\n",
    "img_viewer = ImagesViewer()\n",
    "for index, (image_data, labels) in enumerate(tfrecord_file.read(tfrecord_filename, theta_dims)):\n",
    "    img_viewer.add_image(image_data.numpy())\n",
    "    if index > MAX_AMOUNT:\n",
    "        break\n",
    "    \n",
    "img_viewer.view_as_slider() "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}